home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4636 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Incrementing enumerated types
  5. Date: Wed, 31 Jan 1996 13:28:47 GMT
  6. Organization: Netcom
  7. Message-ID: <310f6d26.50322368@nntp.ix.netcom.com>
  8. References: <Andy.Law-3101961138310001@pc0734.ri.bbsrc.ac.uk>
  9. NNTP-Posting-Host: ix-dc6-05.ix.netcom.com
  10. X-NETCOM-Date: Wed Jan 31  5:29:09 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Andy.Law@bbsrc.ac.uk (Andy Law) wrote:
  14.  
  15. > Is it legal to increment an enumerated type? I have an enumerated list of
  16. > possible document types that I want to step through, and my compiler is
  17. > barfing on it. It seems such a waste of an enumeration if I have to resort
  18. > to ints to get this done.
  19. > Alternatively does anyone have a suggestion as to how to do this kind of
  20. > thing legally?
  21. > for (EnumeratedType eIndex = enum_first; eIndex < enum_last; eIndex++) {
  22. >                                                              ^^^^^^^^
  23. >     /* do something */
  24. > }
  25.  
  26. You've posted to both comp.lang.c and comp.lang.c++.
  27.  
  28. Answer from comp.lang.c:
  29.  
  30.     Incrementing an enum is legal.  Your compiler should have 
  31.     given a diagnostic for your syntax in the for statement.  A 
  32.     for statement may not include a declaration in any of the 
  33.     expressions.
  34.  
  35. Answer from comp.lang.c++:
  36.  
  37.     It is illegal to increment an enum unless you have overloaded 
  38.     operator++ for the enum (overloading for enum types a new 
  39.     feature and is not supported by many compilers yet).  You can 
  40.     get the effect you want with a cast:
  41.  
  42.     for (EnumeratedType eIndex = enum_first; 
  43.          eIndex < enum_last; 
  44.          eIndex = EnumeratedType(eIndex + 1))
  45.  
  46.  
  47. Michael M Rubenstein
  48.